package com.thread;

/**
 * Created by john on 2016/4/7.
 * 通过stop来停止线程，会导致程序流程错误
 */
public class ThreadTest4  extends Thread{

    private MyObject object;
    public ThreadTest4(MyObject object){
        super();
        this.object = object;
    }

    @Override
    public void run() {
        object.printStr("b","bb");
    }

    public static void main(String[] args) {
        MyObject object = new MyObject();
        ThreadTest4 test = new ThreadTest4(object);
        test.start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        test.stop();
        System.out.println(object.getName()+":"+object.getPass());
    }
}

class MyObject{

    private String name ="a";
    private String pass = "aa";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public void printStr(String name,String pass) {
        this.name = name;
        System.out.println("name:"+name);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.pass = pass;
        System.out.println("pass:"+pass);
    }
}